#include<iostream>
using namespace std;

int t;
long long int n,a[200001],c[200001];
bool col[200001],coll0[200001];
int akk[1000];

void ejz(int x){
        int count0 = 0;
        while(x != 1){
                col[count0] = x % 2;
                x = x / 2;
                count0++;
        }
        col[count0] = 1;
        count0++;
        for(int i = 0;i < count0;i++){
                coll0[i] = col[count0 - i];
                cout<<coll0[i]<<"   "<<col[count0 - i]<<endl;
        }
}

void wkt(int x){
        for(int i = 0;i < n;i++){
                if(i == 0) {
                        c[i] = 0;
                        continue;
                }
                for(int j = i;j>=0;j--){
                        if((coll0[i] = coll0[j]) && (a[i] == a[j])) c[i] = a[i];
                        else c[i] = 0;
                }
        akk[x] = akk[x] + c[i];
        }
}

int main(){
        freopen("color.in","r",stdin);
        freopen("color.out","w",stdout);
        int wmax = -999;
        cin>>t;
        for(int w = 0;w < t;w++){
                cin>>n;
                for(int i = 0;i < n;i++){
                        cin>>a[i];
                        c[i] = 0;
                }
                //bao li mei ju
                for(int i = 0;i < n * n + 1;i++){
                        ejz(i);
                        wkt(i);
                        if(akk[i] > wmax) wmax = akk[i];
                }
                cout<<wmax<<endl;
        }
        return 0;
}
